package com.example.designpatterns.decorator;

// 客户端代码：演示如何使用装饰器模式
public class DecoratorPatternDemo {
    public static void main(String[] args) {
        // 创建原始文本
        TextComponent simpleText = new SimpleText("Hello, World!");

        // 显示原始文本
        System.out.println("== 原始文本 ==");
        simpleText.display();
        System.out.println();

        // 单个装饰器示例
        System.out.println("== 单个装饰器 ==");
        
        TextComponent boldText = new BoldDecorator(simpleText);
        System.out.println("加粗文本:");
        boldText.display();
        
        TextComponent italicText = new ItalicDecorator(simpleText);
        System.out.println("斜体文本:");
        italicText.display();
        
        TextComponent underlineText = new UnderlineDecorator(simpleText);
        System.out.println("下划线文本:");
        underlineText.display();
        
        TextComponent redText = new ColorDecorator(simpleText, ColorDecorator.RED);
        System.out.println("红色文本:");
        redText.display();
        System.out.println();

        // 组合多个装饰器
        System.out.println("== 组合装饰器 ==");
        
        // 红色加粗文本
        TextComponent redBoldText = new ColorDecorator(
                new BoldDecorator(simpleText), 
                ColorDecorator.RED);
        System.out.println("红色加粗文本:");
        redBoldText.display();
        
        // 蓝色斜体文本
        TextComponent blueItalicText = new ColorDecorator(
                new ItalicDecorator(simpleText), 
                ColorDecorator.BLUE);
        System.out.println("蓝色斜体文本:");
        blueItalicText.display();
        
        // 绿色带下划线文本
        TextComponent greenUnderlineText = new ColorDecorator(
                new UnderlineDecorator(simpleText), 
                ColorDecorator.GREEN);
        System.out.println("绿色带下划线文本:");
        greenUnderlineText.display();
        
        // 红色加粗斜体文本
        TextComponent redBoldItalicText = new ColorDecorator(
                new BoldDecorator(
                    new ItalicDecorator(simpleText)), 
                ColorDecorator.RED);
        System.out.println("红色加粗斜体文本:");
        redBoldItalicText.display();
        
        // 演示装饰器的灵活性：不同顺序的装饰器效果
        System.out.println("\n== 装饰顺序对比 ==");
        
        // 先加粗后着色
        TextComponent boldThenColor = new ColorDecorator(
                new BoldDecorator(simpleText), 
                ColorDecorator.GREEN);
        System.out.println("先加粗后着色:");
        boldThenColor.display();
        
        // 先着色后加粗
        TextComponent colorThenBold = new BoldDecorator(
                new ColorDecorator(simpleText, ColorDecorator.GREEN));
        System.out.println("先着色后加粗:");
        colorThenBold.display();
        
        // 获取内容不显示
        System.out.println("\n== 仅获取内容 ==");
        String complexContent = new UnderlineDecorator(
                new BoldDecorator(
                    new ColorDecorator(simpleText, ColorDecorator.BLUE)
                )
            ).getContent();
        System.out.println("复杂装饰后的内容:\n" + complexContent);
    }
}